import Taro, { Current } from '@tarojs/taro'
import React, { PureComponent } from 'react'
// 界面组件
import { View, Text, Button, Image } from '@tarojs/components'
import { AtAvatar, AtIcon } from 'taro-ui'

import CTopbar from '../../../components/CTopBar/index'
import { get_consulting_data, isLike_api } from './service'
import Appointmentsuccessful from '@/assets/Appointmentsuccessful.png'
import './index.scss'
import GetTopBarInfo from '@/utils/GetTopBarInfo' //动态高度
/**
 * 咨询界面
 */

interface I {
  therapistName: string
  consultTeacherType: string
  status: number
}

interface Consulting {
  state: I
}

class Consulting extends PureComponent<any> {
  constructor(props) {
    super(props)
    this.state = {
      therapistName: '',
      consultTeacherType: '',
      status: 0,
    }
  }
  //WARNING! To be deprecated in React v17. Use componentDidMount instead.
  componentWillMount() {
    const { therapistName, consultTeacherType, status } = Current.router?.params
    this.setState({
      therapistName,
      consultTeacherType,
      status: Number(status),
    })
  }
  goto_orderPage() {
    const { status } = this.state

    //成功:0   失败：1
    Taro.reLaunch({
      url: '/pages/My/MyReservation/index?tabType=' + status,
    })
  }

  render() {
    const { therapistName, consultTeacherType, status } = this.state
    const consultTeacherTypeArr = ['', '高级', '资深', '主任', '专家']
    return (
      <View style={{ paddingTop: `${GetTopBarInfo().TopBarHeight}px` }}>
        <View className='header'>
          <CTopbar title='预约' showBack></CTopbar>
        </View>
        <View className='content'>
          <Image src={Appointmentsuccessful} />
          {/* //成功:0   失败：1 */}
          {status === 0 ? <Text className='result'>恭喜你，预约成功</Text> : <Text className='result_err'>对不起，预约失败</Text>}
          <Text className='tips'>客服人员会在24小时主动联系您，请保持手机正常通信</Text>
          <Text className='consultingName'>
            预约咨询师：{therapistName} 国家{consultTeacherTypeArr[consultTeacherType]}心理咨询师
          </Text>
          <Text className='showOrder' onClick={this.goto_orderPage.bind(this)}>
            查看订单
          </Text>
        </View>
      </View>
    )
  }
}

export default Consulting
